/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.revdev.streckenliste.managedbeans.validator;

import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author f.lindermaier
 */
@FacesValidator(value = "pastDateValidator")
public class DatePastValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        java.util.Date validate = (java.util.Date) value;

        Calendar cal = Calendar.getInstance();
        Calendar current = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH) + 1);
        if (validate.after(current.getTime())) {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Das Datum liegt in der Zukunft", "Das Datum liegt in der Zukunft"));
        }


    }
}
